﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Silverlight.Testing;
using System.IO;

namespace ThemeLoader.Test.Integration
{
    /// <summary>
    /// See myDeck.MSTest.Runner.Web for style folders
    /// </summary>
    [TestClass]
    public class ThemeLoaderTests : SilverlightTest
    {
        private ThemeLoader themeLoader;

        [TestInitialize]
        public void SetUpTest()
        {
            themeLoader = new ThemeLoader();
        }

        [TestMethod]
        [Asynchronous]
        public void DownloadTheme_ProperPath_ThemeContainsKey()
        {
            themeLoader.DownloadTheme("CompressedThemes/theme1.zip", "theme1.xaml", e => 
            {
                Assert.IsTrue(e.Result.Contains("buttonStyle"));
                base.EnqueueTestComplete();
            });
        }

        [TestMethod]
        [Asynchronous]
        public void DownloadTheme_InproperResourcePath_ErrorNotNull()
        {
            themeLoader.DownloadTheme("CompressedThemesAgegbegeb/theme1.zip", "theme1.xaml", e =>
            {
                Assert.IsNotNull(e.Error);
                base.EnqueueTestComplete();
            });
        }

        [TestMethod]
        [Asynchronous]
        public void DownloadTheme_InproperStylesheetName_ErrorNotNull()
        {
            themeLoader.DownloadTheme("CompressedThemes/theme1.zip", "theme1aggebege.xaml", e =>
            {
                Assert.IsNotNull(e.Error);
                base.EnqueueTestComplete();
            });
        }

        [TestMethod]
        [Asynchronous]
        public void DownloadAsyncZippedStream_ProperPath_StreamLenghtGreaterThan0()
        {
            themeLoader.DownloadAsyncZippedStream("CompressedThemes/theme1.zip", e =>
                {
                    Assert.IsTrue(e.Result.Length > 0);
                    base.EnqueueTestComplete();
                });
        }

        [TestMethod]
        [Asynchronous]
        public void DownloadAsyncZippedStream_InproperPath_ErrorNotNull()
        {
            themeLoader.DownloadAsyncZippedStream("CompressedThemesAgegbegeb/theme1.zip", e =>
            {
                Assert.IsNotNull(e.Error);
                base.EnqueueTestComplete();
            });
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void GetThemeFromZipStream_StreamNull_ArgumentNullException()
        {
            themeLoader.GetThemeFromZipStream(null, "agebe");
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void GetThemeFromZipStream_PathNull_ArgumentNullException()
        {
            themeLoader.GetThemeFromZipStream(new MemoryStream(), null);
        }

        [TestMethod]
        [ExpectedException(typeof(ThemeLoadException))]
        public void GetThemeFromZipStream_InvalidStream_ThemeLoadException()
        {
            themeLoader.GetThemeFromZipStream(new MemoryStream(), "theme1.xaml");
        }

        [TestMethod]
        [ExpectedException(typeof(ThemeLoadException))]
        public void GetThemeFromZipStream_InvalidPath_ThemeLoadException()
        {
            themeLoader.GetThemeFromZipStream(new MemoryStream(), "agebeg");
        }
    }
}
